/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86186
 * Date: 2023-10-14
 * Time: 14:56
 */
public class Test {
    public int getLCA(int a, int b) {
        // write code here
        return getLCAChild(a, b, 1);
    }

    private int getLCAChild(int a, int b, int p) {
        if (p >= 1000) return -1;
        if (p == a || p == b) return p;
        int l = getLCAChild(a, b, 2 * p);
        int r = getLCAChild(a, b, 2 * p + 1);

        if (l != -1 && r != -1) return p;
        else if (l != -1) return l;
        else if(r != -1) return r;
        return -1;
    }
}
